//
//  SchoolViewController.m
//  四年
//
//  Created by 中软国际088 on 15/11/3.
//  Copyright © 2015年 小二. All rights reserved.
//
#import "SchoolViewController.h"
#import "NomalNewsTableViewCell.h"
#import "ImageNewsTableViewCell.h"

#define ContentView_Height (HEIGHT - NaviBar_Height - TabBar_Height)
#define ScrollNews_LineView_Y 180

@interface SchoolViewController () <UITableViewDataSource, UIScrollViewDelegate>
{
    UIScrollView *scrollNewsView;
    UIImageView *scrollNewsTypeView;
    UILabel *scrollNewsTitleView;
    UIPageControl *scrollNewsPageControlView;
}
@property (strong, nonatomic) UITableView *newsTableView;

@end

@implementation SchoolViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:NO];
}

- (void)viewWillLayoutSubviews {
    /*****************第 1 页：校 园 新 闻 界 面******************/
    
    _newsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, ContentView_Height) style:UITableViewStylePlain];
    _newsTableView.dataSource = self;
////    
//    newsTableView.estimatedRowHeight = 50.;
    //第一种Cell高度
//    newsTableView.rowHeight = UITableViewAutomaticDimension;
    _newsTableView.rowHeight = 85;
//    //第二种Cell高度
//    newsTableView.rowHeight = UITableViewAutomaticDimension;
//    newsTableView.rowHeight = 120;
    
    [self.scrollView addSubview:_newsTableView];
    
    //tableHeaderView - 滚 动 新 闻
    
    UIView * tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, ScrollNews_LineView_Y + 35)];
    _newsTableView.tableHeaderView = tableHeaderView;

    scrollNewsView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, ScrollNews_LineView_Y)];
    scrollNewsView.showsHorizontalScrollIndicator = NO;
    scrollNewsView.pagingEnabled = YES;
    scrollNewsView.bounces = NO;
    scrollNewsView.delegate = self;
    scrollNewsView.contentSize = CGSizeMake(WIDTH * 4, 0);
    [tableHeaderView addSubview:scrollNewsView];
    for (int i = 0; i < 4; i ++) {
        UIImageView *scrollNewsIamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT)];
        scrollNewsIamgeView.image = [UIImage imageNamed:@"中心组学习1.jpg"];
        [scrollNewsView addSubview:scrollNewsIamgeView];
    }
    
    scrollNewsTypeView = [[UIImageView alloc] initWithFrame:CGRectMake(7, ScrollNews_LineView_Y + 3, 18, 18)];
    scrollNewsTypeView.image = [UIImage imageNamed:@"cell_tag_photo@2x"];
    [tableHeaderView addSubview:scrollNewsTypeView];
    
    scrollNewsTitleView = [[UILabel alloc] initWithFrame:CGRectMake(35, ScrollNews_LineView_Y, 260, 25)];
    scrollNewsTitleView.textColor = [UIColor colorWithWhite:0.2 alpha:1];
    scrollNewsTitleView.text = @"test000000";
    [tableHeaderView addSubview:scrollNewsTitleView];
    
    scrollNewsPageControlView = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH - 40, ScrollNews_LineView_Y + 12.5, 0, 0)];
    scrollNewsPageControlView.numberOfPages = 4;
    scrollNewsPageControlView.pageIndicatorTintColor = [UIColor lightGrayColor];
    scrollNewsPageControlView.currentPageIndicatorTintColor = [UIColor blackColor];
    [tableHeaderView addSubview:scrollNewsPageControlView];
    /*****************第 2 页：二 手 市 场 界 面******************/
    
    /*****************第 3 页：失 物 招 领 界 面******************/
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"cellIdentifier";
    NomalNewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[NomalNewsTableViewCell alloc] init];
    }
    [cell setNewsImage:@"dian@2x副本" newsTitle:@"今天我测试了第一页aaaaaa" newsDetail:@"今天我测试了第一页,但是我特别的生气，啊啊啊啊啊啊啊" followUpPost:1];
    return cell;
}

- (UIColor *)randomColor {
    return [UIColor colorWithRed:arc4random_uniform(256)/255.0
                           green:arc4random_uniform(256)/255.0
                            blue:arc4random_uniform(256)/255.0
                           alpha:1];
}
#pragma mark - 新闻页 scrollView X pageControl
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (scrollView == scrollNewsView) {
        float indexf = scrollNewsView.contentOffset.x / WIDTH;
        if (indexf - (int)indexf < CGFLOAT_MIN /*浮点数判断*/ ) {
            int index = (int)indexf;
            scrollNewsPageControlView.currentPage = index;
            scrollNewsTitleView.text = @[@"test000000",@"test111111",@"test22222",@"test33333"][index];
            
        }
    }
}
@end
